﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectSchedule.Entity
{
    public class XZSectionProgress_Section
    {
        // 工程号
        public string ShipName { get; set; }
        // 分段名称
        public string SectionName { get; set; }
        // 重量
        public double Weight { get; set; }
        // 开工日
        public DateTime BeginDate { get; set; }
        public double BeginPrecent { get; set; }
        // 完工日
        public DateTime EndDate { get; set; }
        public double EndPrecent { get; set; }

        public string UnitName { get; set; }

        public DateTime PlanStartDate { get; set; }
        public DateTime PlanEndDate { get; set; }
        public Int32 PlanDays
        {
            get
            {
                return (PlanEndDate - PlanStartDate).Days + 1;
            }
        }
        public bool IsBegin
        {
            get
            {
                return BeginDate.Equals(PlanStartDate);
            }
        }
        public bool IsComplete
        {
            get
            {
                return EndDate.Equals(PlanEndDate);
            }
        }

        public static XZSectionProgress_Section GetProgerssByPlan(XZSectionPlan_Section Plan, XZProgressType_Section Type, DateTime beginDate, DateTime endDate)
        {
            var model = new XZSectionProgress_Section();
            model.ShipName = Plan.ShipName;
            model.SectionName = Plan.SectionName;
            model.Weight = Plan.Weight;
            switch (Type)
            {
                case XZProgressType_Section.Pretreat:
                    if (Plan.PretreatStop < beginDate ||
                        Plan.PretreatStart > endDate ||
                        Plan.PlanSectionTime.Pretreat <= 0)
                    {
                        return null;
                    }
                    model.PlanStartDate = Plan.PretreatStart;
                    model.PlanEndDate = Plan.PretreatStop;
                    model.BeginDate = Plan.PretreatStart <= beginDate ? beginDate : Plan.PretreatStart;
                    model.EndDate = Plan.PretreatStop >= endDate ? endDate : Plan.PretreatStop;
                    model.BeginPrecent = (model.BeginDate - Plan.PretreatStart).Days * 100 / Plan.PlanSectionTime.Pretreat;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.PretreatStart).Days * 100 / Plan.PlanSectionTime.Pretreat;
                    model.UnitName = Plan.Units.PretreatUnit;
                    break;
                case XZProgressType_Section.Molding:
                    if (Plan.MoldingStop < beginDate ||
                        Plan.MoldingStart > endDate ||
                        Plan.PlanSectionTime.Molding <= 0)
                    {
                        return null;
                    }
                    model.PlanStartDate = Plan.MoldingStart;
                    model.PlanEndDate = Plan.MoldingStop;
                    model.BeginDate = Plan.MoldingStart <= beginDate ? beginDate : Plan.MoldingStart;
                    model.EndDate = Plan.MoldingStop >= endDate ? endDate : Plan.MoldingStop;
                    model.BeginPrecent = (model.BeginDate - Plan.MoldingStart).Days * 100 / Plan.PlanSectionTime.Molding;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.MoldingStart).Days * 100 / Plan.PlanSectionTime.Molding;
                    model.UnitName = Plan.Units.MoldingUnit;
                    break;
                case XZProgressType_Section.Cutting:
                    if (Plan.CuttingStop < beginDate ||
                        Plan.CuttingStart > endDate ||
                        Plan.PlanSectionTime.Cutting <= 0)
                    {
                        return null;
                    }
                    model.PlanStartDate = Plan.CuttingStart;
                    model.PlanEndDate = Plan.CuttingStop;
                    model.BeginDate = Plan.CuttingStart <= beginDate ? beginDate : Plan.CuttingStart;
                    model.EndDate = Plan.CuttingStop >= endDate ? endDate : Plan.CuttingStop;
                    model.BeginPrecent = (model.BeginDate - Plan.CuttingStart).Days * 100 / Plan.PlanSectionTime.Cutting;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.CuttingStart).Days * 100 / Plan.PlanSectionTime.Cutting;
                    model.UnitName = Plan.Units.CuttUnit;
                    break;
                case XZProgressType_Section.Weld:
                    if (Plan.WeldStop < beginDate ||
                        Plan.WeldStart > endDate ||
                        Plan.PlanSectionTime.Weld <= 0)
                        return null;
                    model.PlanStartDate = Plan.WeldStart;
                    model.PlanEndDate = Plan.WeldStop;
                    model.BeginDate = Plan.WeldStart <= beginDate ? beginDate : Plan.WeldStart;
                    model.EndDate = Plan.WeldStop >= endDate ? endDate : Plan.WeldStop;
                    model.BeginPrecent = (model.BeginDate - Plan.WeldStart).Days * 100 / Plan.PlanSectionTime.Weld;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.WeldStart).Days * 100 / Plan.PlanSectionTime.Weld;
                    model.UnitName = Plan.Units.WeldUnit;
                    break;
                case XZProgressType_Section.Polish:
                    if (Plan.PolishStop < beginDate ||
                        Plan.PolishStart > endDate ||
                        Plan.PlanSectionTime.Polish <= 0)
                    {
                        return null;
                    }
                    model.PlanStartDate = Plan.PolishStart;
                    model.PlanEndDate = Plan.PolishStop;
                    model.BeginDate = Plan.PolishStart <= beginDate ? beginDate : Plan.PolishStart;
                    model.EndDate = Plan.PolishStop >= endDate ? endDate : Plan.PolishStop;
                    model.BeginPrecent = (model.BeginDate - Plan.PolishStart).Days * 100 / Plan.PlanSectionTime.Polish;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.PolishStart).Days * 100 / Plan.PlanSectionTime.Polish;
                    model.UnitName = Plan.Units.PolishUnit;
                    break;
                case XZProgressType_Section.Intest:
                    if (Plan.IntestStop < beginDate ||
                        Plan.IntestStart > endDate ||
                        Plan.PlanSectionTime.Intest <= 0)
                    {
                        return null;
                    }
                    model.PlanStartDate = Plan.IntestStart;
                    model.PlanEndDate = Plan.IntestStop;
                    model.BeginDate = Plan.IntestStart <= beginDate ? beginDate : Plan.IntestStart;
                    model.EndDate = Plan.IntestStop >= endDate ? endDate : Plan.IntestStop;
                    model.BeginPrecent = (model.BeginDate - Plan.IntestStart).Days * 100 / Plan.PlanSectionTime.Intest;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.IntestStart).Days * 100 / Plan.PlanSectionTime.Intest;
                    model.UnitName = Plan.Units.IntestUnit;
                    break;
                case XZProgressType_Section.Preassemble:
                    if (Plan.PreassembleStop < beginDate ||
                        Plan.PreassembleStart > endDate ||
                        Plan.PlanSectionTime.Preassemble <= 0)
                    {
                        return null;
                    }
                    model.PlanStartDate = Plan.PreassembleStart;
                    model.PlanEndDate = Plan.PreassembleStop;
                    model.BeginDate = Plan.PreassembleStart <= beginDate ? beginDate : Plan.PreassembleStart;
                    model.EndDate = Plan.PreassembleStop >= endDate ? endDate : Plan.PreassembleStop;
                    model.BeginPrecent = (model.BeginDate - Plan.PreassembleStart).Days * 100 / Plan.PlanSectionTime.Preassemble;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.PreassembleStart).Days * 100 / Plan.PlanSectionTime.Preassemble;
                    model.UnitName = Plan.Units.IntestUnit;
                    break;
                default:
                    return null;
            }
            return model;
        }
    }

    public class XZSectionProgress_Area
    {
        // 工程号
        public string ShipName { get; set; }
        // 分段名称
        public string AreaName { get; set; }
        // 重量
        public double Weight { get; set; }
        // 开工日
        public DateTime BeginDate { get; set; }
        public double BeginPrecent { get; set; }
        // 完工日
        public DateTime EndDate { get; set; }
        public double EndPrecent { get; set; }

        public string UnitName { get; set; }
        public DateTime PlanStartDate { get; set; }
        public DateTime PlanEndDate { get; set; }
        public Int32 PlanDays
        {
            get
            {
                return (PlanEndDate - PlanStartDate).Days + 1;
            }
        }
        public bool IsBegin
        {
            get
            {
                return BeginDate.Equals(PlanStartDate);
            }
        }
        public bool IsComplete
        {
            get
            {
                return EndDate.Equals(PlanEndDate);
            }
        }

        public static XZSectionProgress_Area GetProgerssByPlan(XZSectionPlan_Area Plan, XZProgressType_Area Type, DateTime beginDate, DateTime endDate)
        {
            var model = new XZSectionProgress_Area();
            model.ShipName = Plan.ShipName;
            model.AreaName = Plan.AreaName;
            model.Weight = Plan.Weight;
            switch (Type)
            {
                case XZProgressType_Area.Pretreat:
                    if (Plan.PretreatStop < beginDate || Plan.PretreatStart > endDate)
                    {
                        return null;
                    }
                    model.PlanStartDate = Plan.PretreatStart;
                    model.PlanEndDate = Plan.PretreatStop;
                    model.BeginDate = Plan.PretreatStart <= beginDate ? beginDate : Plan.PretreatStart;
                    model.EndDate = Plan.PretreatStop >= endDate ? endDate : Plan.PretreatStop;
                    model.BeginPrecent = (model.BeginDate - Plan.PretreatStart).Days * 100 / Plan.PlanAreaTime.Pretreat;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.PretreatStart).Days * 100 / Plan.PlanAreaTime.Pretreat;
                    model.UnitName = Plan.Units.PretreatUnit;
                    break;
                case XZProgressType_Area.Molding:
                    if (Plan.MoldingStop < beginDate || Plan.MoldingStart > endDate)
                    {
                        return null;
                    }
                    model.PlanStartDate = Plan.MoldingStart;
                    model.PlanEndDate = Plan.MoldingStop;
                    model.BeginDate = Plan.MoldingStart <= beginDate ? beginDate : Plan.MoldingStart;
                    model.EndDate = Plan.MoldingStop >= endDate ? endDate : Plan.MoldingStop;
                    model.BeginPrecent = (model.BeginDate - Plan.MoldingStart).Days * 100 / Plan.PlanAreaTime.Molding;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.MoldingStart).Days * 100 / Plan.PlanAreaTime.Molding;
                    model.UnitName = Plan.Units.MoldingUnit;
                    break;
                case XZProgressType_Area.Cutting:
                    if (Plan.CuttingStop < beginDate || Plan.CuttingStart > endDate)
                    {
                        return null;
                    }
                    model.PlanStartDate = Plan.CuttingStart;
                    model.PlanEndDate = Plan.CuttingStop;
                    model.BeginDate = Plan.CuttingStart <= beginDate ? beginDate : Plan.CuttingStart;
                    model.EndDate = Plan.CuttingStop >= endDate ? endDate : Plan.CuttingStop;
                    model.BeginPrecent = (model.BeginDate - Plan.CuttingStart).Days * 100 / Plan.PlanAreaTime.Cutting;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.CuttingStart).Days * 100 / Plan.PlanAreaTime.Cutting;
                    model.UnitName = Plan.Units.CuttUnit;
                    break;
                case XZProgressType_Area.Weld:
                    if (Plan.WeldStop < beginDate || Plan.WeldStart > endDate)
                        return null;
                    model.PlanStartDate = Plan.WeldStart;
                    model.PlanEndDate = Plan.WeldStop;
                    model.BeginDate = Plan.WeldStart <= beginDate ? beginDate : Plan.WeldStart;
                    model.EndDate = Plan.WeldStop >= endDate ? endDate : Plan.WeldStop;
                    model.BeginPrecent = (model.BeginDate - Plan.WeldStart).Days * 100 / Plan.PlanAreaTime.Weld;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.WeldStart).Days * 100 / Plan.PlanAreaTime.Weld;
                    model.UnitName = Plan.Units.WeldUnit;
                    break;
                case XZProgressType_Area.Polish:
                    if (Plan.PolishStop < beginDate || Plan.PolishStart > endDate)
                    {
                        return null;
                    }
                    model.PlanStartDate = Plan.PolishStart;
                    model.PlanEndDate = Plan.PolishStop;
                    model.BeginDate = Plan.PolishStart <= beginDate ? beginDate : Plan.PolishStart;
                    model.EndDate = Plan.PolishStop >= endDate ? endDate : Plan.PolishStop;
                    model.BeginPrecent = (model.BeginDate - Plan.PolishStart).Days * 100 / Plan.PlanAreaTime.Polish;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.PolishStart).Days * 100 / Plan.PlanAreaTime.Polish;
                    model.UnitName = Plan.Units.PolishUnit;
                    break;
                case XZProgressType_Area.Intest:
                    if (Plan.IntestStop < beginDate || Plan.IntestStart > endDate)
                    {
                        return null;
                    }
                    model.PlanStartDate = Plan.IntestStart;
                    model.PlanEndDate = Plan.IntestStop;
                    model.BeginDate = Plan.IntestStart <= beginDate ? beginDate : Plan.IntestStart;
                    model.EndDate = Plan.IntestStop >= endDate ? endDate : Plan.IntestStop;
                    model.BeginPrecent = (model.BeginDate - Plan.IntestStart).Days * 100 / Plan.PlanAreaTime.Intest;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.IntestStart).Days * 100 / Plan.PlanAreaTime.Intest;
                    model.UnitName = Plan.Units.IntestUnit;
                    break;
                case XZProgressType_Area.Bulk:
                    if (Plan.BulkStop < beginDate || Plan.BulkStart > endDate)
                    {
                        return null;
                    }
                    model.PlanStartDate = Plan.BulkStart;
                    model.PlanEndDate = Plan.BulkStop;
                    model.BeginDate = Plan.BulkStart <= beginDate ? beginDate : Plan.BulkStart;
                    model.EndDate = Plan.BulkStop >= endDate ? endDate : Plan.BulkStop;
                    model.BeginPrecent = (model.BeginDate - Plan.BulkStart).Days * 100 / Plan.PlanAreaTime.Bulk;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.BulkStart).Days * 100 / Plan.PlanAreaTime.Bulk;
                    model.UnitName = Plan.Units.BulkUnit;
                    break;
                case XZProgressType_Area.DockProject:
                    if (Plan.DockProjectStop < beginDate || Plan.DockProjectStart > endDate)
                    {
                        return null;
                    }
                    model.PlanStartDate = Plan.DockProjectStart;
                    model.PlanEndDate = Plan.DockProjectStop;
                    model.BeginDate = Plan.DockProjectStart <= beginDate ? beginDate : Plan.DockProjectStart;
                    model.EndDate = Plan.DockProjectStop >= endDate ? endDate : Plan.DockProjectStop;
                    model.BeginPrecent = (model.BeginDate - Plan.DockProjectStart).Days * 100 / Plan.PlanAreaTime.DockProject;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.DockProjectStart).Days * 100 / Plan.PlanAreaTime.DockProject;
                    model.UnitName = Plan.Units.DockProjectUnit;
                    break;
                default:
                    return null;
            }
            return model;
        }
    }

    public class XZSectionProgress_Debug
    {
        // 工程号
        public string ShipName { get; set; }
        // 工程名称
        public string ProjectName { get; set; }
        // 开工日
        public DateTime BeginDate { get; set; }
        public double BeginPrecent { get; set; }
        // 完工日
        public DateTime EndDate { get; set; }
        public double EndPrecent { get; set; }

        public string UnitName { get; set; }

        public DateTime PlanStartDate { get; set; }
        public DateTime PlanEndDate { get; set; }
        public Int32 PlanDays
        {
            get
            {
                return (PlanEndDate - PlanStartDate).Days + 1;
            }
        }
        public bool IsBegin
        {
            get
            {
                return BeginDate.Equals(PlanStartDate);
            }
        }
        public bool IsComplete
        {
            get
            {
                return EndDate.Equals(PlanEndDate);
            }
        }

        public static XZSectionProgress_Debug GetProgerssByPlan(XZSectionPlan_Debug Plan, XZProgressType_Debug Type, DateTime beginDate, DateTime endDate)
        {
            var model = new XZSectionProgress_Debug();
            model.ShipName = Plan.ShipName;
            model.ProjectName = Plan.ProjectName;
            switch (Type)
            {
                case XZProgressType_Debug.Debugging:
                    if (Plan.DebuggingStop < beginDate || Plan.DebuggingStart > endDate)
                    {
                        return null;
                    }
                    model.PlanStartDate = Plan.DebuggingStart;
                    model.PlanEndDate = Plan.DebuggingStop;
                    model.BeginDate = Plan.DebuggingStart <= beginDate ? beginDate : Plan.DebuggingStart;
                    model.EndDate = Plan.DebuggingStop >= endDate ? endDate : Plan.DebuggingStop;
                    model.BeginPrecent = (model.BeginDate - Plan.DebuggingStart).Days * 100 / Plan.PlanTime.Debugging;
                    model.EndPrecent = (model.EndDate.AddDays(1) - Plan.DebuggingStart).Days * 100 / Plan.PlanTime.Debugging;
                    model.UnitName = Plan.Units.DebuggingUnit;
                    break;
                default:
                    return null;
            }
            return model;
        }
    }
}
